import 'package:core/core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'router/route_names.dart';
import 'router/app_routers.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      debugShowCheckedModeBanner: false,
      title: AppConfig.appName,
      theme: getAppThemeData(),
      localizationsDelegates: const [
        RefreshLocalizations.delegate,
        GlobalMaterialLocalizations.delegate, // 指定本地化的字符串和一些其他的值
        GlobalCupertinoLocalizations.delegate, // 对应的Cupertino风格
        GlobalWidgetsLocalizations.delegate, // 指定默认的文本排列方向, 由左到右或由右到左
      ],
      locale: const Locale('zh', 'CN'),
      supportedLocales: const [Locale('zh', 'CH'), Locale('en', 'US')],
      routerConfig: AppRouter.router,
      builder: (context, widget) {
        return MediaQuery(
          data: MediaQuery.of(
            context,
          ).copyWith(textScaler: TextScaler.linear(1.0)),
          child: widget!, //设置文字大小不随系统设置改变
        );
      },
    );
  }

  String initRouteName() {
    return RouteNames.guide;
  }

  ThemeData getAppThemeData() {
    return ThemeData(
      colorScheme: ColorScheme.fromSeed(seedColor: Colors.black),
      scaffoldBackgroundColor: Colors.white,
    );
  }
}
